#ifndef __RESULT_CONVERTER_H__
#define __RESULT_CONVERTER_H__

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include "common.h"
#include "Reference.h"
#include "QuerySet.h"
#include "SAResult.h"

using namespace std;

class ResultConverter {
private:
	Reference* ref;
	unsigned int* saIndex;
	QuerySet* querySet;
	SAResult* saResult;
	unsigned long _numSA;
	unsigned long _numAlignment;
	unsigned long _numQuery;
	int _readLength;
public:
	ResultConverter(Reference &i_ref, unsigned int* i_saIndex) : 
			ref(&i_ref), saIndex(i_saIndex), 
			querySet(NULL), saResult(NULL) {};
	~ResultConverter();

	inline void prepare(QuerySet* i_querySet, SAResult* i_saResult) {
		querySet = i_querySet;
		saResult = i_saResult;
		_numQuery = querySet->numQuery;
		_readLength = querySet->readLength;
		_numSA = saResult->numSA;
		_numAlignment = saResult->numAlignment();
	}

	//get the single column of the output
	unsigned int* getPos();
	int* getHit();
	char* getQscore();
	char* getStrand();
	//for efficiency, it requires the strand after calling getStrand
	void getMismatch(uchar2 *&offset, char2 *&sub, const char* strand);

	//output the alignment using the 2bwt format
	void output_2bwt(string fileName);

private:
	void mismatchSingle(uchar2 &offset, char2 &sub,
				 const char* read, const unsigned long pos);

	unsigned long getQid(const uint3 sa);
};

#endif /*__RESULT_CONVERTER_H__*/
